import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;

@WebServlet("/show")
public class ShowRequestServlet  extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
         StringBuilder builder = new StringBuilder() ;
         builder.append(req.getMethod()) ;
         builder.append("<br>") ;
         builder.append(req.getRequestURI()) ;
        builder.append("<br>") ;
        builder.append(req.getContextPath()) ;
        builder.append("<br>") ;
        builder.append(req.getProtocol()) ;
        builder.append("<br>") ;
        builder.append(req.getQueryString()) ;
        builder.append("<br>") ;

        Enumeration<String> enumeration = req.getHeaderNames() ;
         while (enumeration.hasMoreElements()){
             String key = enumeration.nextElement() ;
             String value = req.getHeader(key) ;
             builder.append("key:"+key+" value:"+value) ;
         }
        builder.append("<br>") ;
        builder.append("服务器") ;
        resp.setContentType("text/html; charset=utf8");

        resp.getWriter().write(builder.toString());
    }
}
